//
//  ZHomeTableViewController.m
//  OC-weibo
//
//  Created by zero on 17/3/19.
//  Copyright © 2017年 zero. All rights reserved.
//

#import "ZHomeTableViewController.h"
#import "ZTempTableViewController.h"
#import "ZHomeViewModel.h"
#import "ZHomeViewTableViewCell.h"

static NSString *home_Cell = @"home_Cell";

@interface ZHomeTableViewController ()

@property (nonatomic,strong)ZHomeViewModel *homeModel;
@end

@implementation ZHomeTableViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
    UIBarButtonItem *btn = [UIBarButtonItem initWithTitle:nil andImageName:@"navigationbar_pop" andTarget:self andSel:@selector(next)];
    
    self.navigationItem.rightBarButtonItem = btn;
    
    
    //  设置tableView的属性
    
    
    [self setTableViewAttr];
    
    //  初始化对象
    self.homeModel = [[ZHomeViewModel alloc] init];
    //  加载数据
    [self loadData];
    
}

#pragma mark
#pragma mark - 设置tableView的属性
- (void)setTableViewAttr{
    
    //  预估行高
    self.tableView.rowHeight = UITableViewAutomaticDimension;
    self.tableView.estimatedRowHeight = 200;
    
    //  注册
    [self.tableView registerClass:[ZHomeViewTableViewCell class] forCellReuseIdentifier:home_Cell];
}
#pragma mark
#pragma mark - 加载数据
- (void)loadData{
 
    [self.homeModel homeDataViewModel:^(BOOL res) {
        
        if (res) {
            
            NSLog(@"home_LoadData 成功");
            
            [self.tableView reloadData];
            
        }else{
            NSLog(@"失败");
        }
    }];
}
#pragma mark
#pragma mark - next
- (void)next{
    
    ZTempTableViewController *tempVC = [[ZTempTableViewController alloc] init];
    
    [self.navigationController pushViewController:tempVC animated:YES];
}




- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return self.homeModel.homeModelList.count;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    ZHomeViewTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:home_Cell forIndexPath:indexPath];
    
    
    cell.homeViewModel = self.homeModel.homeModelList[indexPath.row];
    
    cell.backgroundColor = [UIColor z_colorWithHex:0xf5f5f9];
    
    //  取消选中状态
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    return cell;
}





@end
